<template>
  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="序号" align="center" prop="id" width="55" />
      <el-table-column label="红娘" align="center" prop="userName" width="80" />
      <el-table-column label="牵线次数" align="center" prop="openNum" width="80">
        <template #default="scope"> {{ scope.row.openNum }}次 </template>
      </el-table-column>
      <el-table-column
        label="服务开始时间"
        align="center"
        prop="createTime"
        :formatter="dateFormatter"
        width="180px"
      />
      <el-table-column
        label="服务结束时间"
        align="center"
        prop="createTime"
        :formatter="dateFormatter"
        width="180px"
      />
      <el-table-column
        label="服务开始时间"
        align="center"
        prop="createTime"
        :formatter="dateFormatter"
        width="180px"
      />
      <el-table-column label="聊天记录" align="center" fixed="right">
        <template #default="scope">
          <el-button link type="primary" @click="openChat(scope.row.recordId)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>

  <!-- 详情弹窗：查看 -->
  <Detail ref="formRefDetail" />
</template>

<script setup lang="ts">
import * as MatchmakerRecordApi from '@/api/blind/maker/matchmakerRecord'
import { dateFormatter } from '@/utils/formatTime'
import Detail from './Detail.vue'
import { useTagsViewStore } from '@/store/modules/tagsView'
import { ElMessage } from 'element-plus'

defineOptions({ name: 'BlindMemberUser' })

const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  userId: undefined
})

/** 查询列表 */
const getList = async (id) => {
  queryParams.userId = id
  loading.value = true
  try {
    const data = await MatchmakerRecordApi.getMatchmakerRecordPage(queryParams)

    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 打开会员详情 */
const formRefDetail = ref()
const openChat = (id?: string) => {
  formRefDetail.value.open(id)
}

/** 初始化 **/
const { currentRoute } = useRouter() // 路由
const { delView } = useTagsViewStore() // 视图操作
const route = useRoute()
const id = Number(route.params.id)
onMounted(() => {
  if (!id) {
    ElMessage.warning('参数错误，会员编号不能为空！')
    delView(unref(currentRoute))
    return
  }
  getList(id)
})
</script>
